define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        //列表
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    table: 'real_order',
                }
            });
            var table = $("#table");
            //当表格数据加载完成时

            table.bootstrapTable({
                url: 'chase/real_order',
                columns: [{
                    field: 'id',
                    title: __('ID'),
                    operate:false
                }, {
                    operate:false,//模糊查询不显示
                    field: 'order_no',
                    title: __('订单'),
                    formatter: Controller.api.order_info
                },{
                    operate:false,//模糊查询不显示
                    field: '',
                    title: __('服务'),
                    formatter: Controller.api.service_name
                },{
                    operate:false,//模糊查询不显示
                    field: '',
                    title: __('单价'),
                    formatter: Controller.api.service_price
                },{
                    operate:false,//模糊查询不显示
                    field: '',
                    title: __('数量'),
                    formatter: Controller.api.service_count
                },{
                    operate:false,//模糊查询不显示
                    field: '',
                    title: __('技师'),
                    formatter: Controller.api.service_technician
                },
                    {
                        visible:false,
                        field: 'orderid',
                        title: __('订单编号'),
                    },
                    {
                        visible:false,//列表不显示,模糊查询显示
                        field: 'ordertime',
                        title: __('下单日期'),
                        operate: 'RANGE',
                        addclass: 'datetimerange',
                        formatter: Table.api.formatter.datetime
                    },
                    {
                        visible:false,//列表不显示,模糊查询显示
                        field: 'userphone',
                        title: __('客户手机')
                    },
                    {
                        operate:false,//模糊查询不显示
                        field: '',
                        title: __('客户'),
                        formatter: Controller.api.user_info,

                    },{
                        field: 'real_amount',
                        title: __('支付金额')
                    },{
                        field: 'payment',
                        title: __('支付方式'),
                        searchList: {"1":__('Payment 1'),"2":__('Payment 2'),"3":__('Payment 3')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                    },{
                        field: 'status',
                        title: __('支付状态'),
                        searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status
                    },
                    {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (e, data) {
                            if (data.status == 1) {
                                payment = ` <a href="javascript:;" class="btn btn-xs btn-success btn-payment" data-id="`+data.id+`">收款</a> `
                                    + ` <a href="javascript:;" class="btn btn-xs btn-warning btn-cancel" data-id="`+data.id+`">取消</a>`;
                            } else {
                                payment = ``;
                            }

                            return ` <a href="javascript:;" class="btn btn-xs btn-primary btn-detail" data-id="`+data.id+`">查看</a>` + payment

                    }}
                ]

            });

            //开单
            $('.myTabContent').on('click', '.btn-add-order', function() {
                Fast.api.open('/shijiu.php/chase/real_order/create', '开单',{area:['100%', '100%']})
            })

            //取消订单
            $('#table').on('click', '.btn-cancel', function () {
                var id = $(this).data('id')
                layer.confirm('您确定要取消吗？', function () {
                    $.post('/shijiu.php/chase/real_order/cancel', {
                        order_id: id
                    }, function (res) {
                        if (res.code == 1) {
                            layer.msg('订单取消成功')
                            setTimeout(()=>{
                                window.location.reload()
                            },1000)
                        } else {
                            layer.msg(res.msg)
                            layer.close(index);
                        }
                    })
                })
            })

            //详情
            $('#table').on('click', '.btn-detail', function () {
                var id = $(this).data('id')
                Fast.api.open('/shijiu.php/chase/real_order/detail?ids='+id, '订单详情')
            })

            //收款
            $('#table').on('click', '.btn-payment', function() {
                var id = $(this).data('id')
                Fast.api.open('/shijiu.php/chase/real_order/payment?ids='+id, '收款',{area:['100%', '100%']})

            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        //开单
        create: function () {

            let that = this
            //用户
            $('#add-form').on('click', '.btn-user', function() {
                Fast.api.open('/shijiu.php/chase/real_order/users', '用户列表',{callback: function (data) {

                        $("#userbox").html(`<table id="table1" class="table table-bordered text-center" width="70%">
					<thead>
					   <tr>
						 <th>客户名称</th>
						 <th>会员等级</th>
						 <th>手机号码</th>
						 <th>操作</th>
					   </tr> 
					</thead>
						  <tbody>
							<tr>
							  <input type="hidden" name="user_id" value="${data.id}">  
							  <td><input readonly class="nostyle" name="nickname" value="${data.nickname}"></td>
							  <td><input readonly class="nostyle" name="vip" value="${data.vip}"></td>
							  <td><input readonly class="nostyle" name="phone" value="${data.phone}"></td>
							  <td>
								  <a href="javascript:;"  class="btn-danger btn-sm userdel">删除</a>
							  </td>
							</tr>
						  </tbody>
					</table>`)
                        $("#input_username").val("1")

                        let total_money = $("input[name='total_amount']").val()
                        let discount_amount = $("input[name='discount_amount']").val()
                        //会员优惠金额
                        let vip_amount = sessionStorage.getItem('discount') * parseFloat(total_money)
                        $("input[name='vip_amount']").val(vip_amount.toFixed(2))

                        //待付款金额
                        let real_amount = total_money - vip_amount - discount_amount;
                        $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)


                    }})

            })
            //数量改变事件
            $('#add-form').on('change',"input[t-id='changefun']",function(){
                let tabList=[];
                let tabListDom=$('#service_table tbody');
                let tabDom = $(tabListDom[0]).children();
                let total_money = 0;
                if(tabDom.length>0){
                    for(let i=0;i<tabDom.length;i++){
                        let thisDom = $(tabDom[i]);
                        let thisIndex = thisDom.prop('id');
                        let nowObj = {
                            service_name:$(tabDom[i]).find(`[name=service_name${thisIndex}]`).val(),
                            price:$(tabDom[i]).find(`[name=price${thisIndex}]`).val(),
                            num:$(tabDom[i]).find(`[name=num${thisIndex}]`).val(),
                            // total:$(tabDom[i]).find(`[name=total${thisIndex}]`).val(),
                            design_id:$(tabDom[i]).find(`[name=design_id${thisIndex}]`).val(),
                        }
                        nowObj.total = nowObj.price * nowObj.num
                        tabList.push(nowObj)
                        total_money += nowObj.total
                        $(`input[name='total${thisIndex}']`).val(nowObj.total.toFixed(2))
                    }

                    //会员优惠金额
                    let vip_amount = sessionStorage.getItem('discount') * total_money
                    //优惠金额
                    let couponDiscount= sessionStorage.getItem('coupon_discount')
                    if (couponDiscount) {
                        var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                        $("input[name='discount_amount']").val(discount_money.toFixed(2))
                    }
                    let discount_amount = $("input[name='discount_amount']").val()
                    //待付款金额
                    let real_amount = total_money - vip_amount - discount_amount;
                    $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                    $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                    //总价格
                    $("input[name='total_amount']").val(total_money.toFixed(2))
                }
                console.log(tabList)
            })
            //服务
            $('#add-form').on('click', '.service', function() {
                Fast.api.open('/shijiu.php/chase/real_order/services', '服务列表',{callback: function (data) {

                        //如果返回的事一个数组是多选服务
                        if(data.length>0){
                            let htmlnew=''
                            let total_money = 0;
                            for(let i = 0 ;i<data.length;i++){
                                if(i==0){
                                    htmlnew=`
									<thead>
									  <tr>
										<th>服务名称</th>
										<th>单价</th>
										<th>数量</th>
										<th>小计</th>
										<th>技师</th>
										<th>操作</th>
									  </tr> 
									</thead>
									  <tr id="${i}">
									    <input type="hidden" name="service_id${i}" value="${data[i].id}">  
										<td><input readonly class="nostyle" name="service_name${i}" value="${data[i].service_name}"></td>
										<td><input readonly class="nostyle" name="price${i}" value="${data[i].service_price}"></td>
										<td><input t-id="changefun" class="w70" type="number" min="0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder1${i}" class="nostyle" name="num${i}" value="1" ><span class="msg-box" id="msg_holder1${i}"></span></td>
										<td><input readonly class="nostyle"  type="number" min="0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder2${i}" class="nostyle" name="total${i}" value="${data[i].service_price}" /><span class="msg-box" id="msg_holder2${i}"></span></td>
										<td>
										    <div class="technician" data-index="${i}">
                                                <div id="choose${i}" class="btn btn-primary"><i class="fa fa-list">选择</i>
                                                <input type="hidden" name="design_id${i}" value="">
                                                <input readonly class="nostyle" data-rule="required" data-msg-required="必填"  data-target="#msg_holder3${i}" name="design_name${i}" style="display:none" value="">
                                                </div>
                                                <span  class="msg-box" id="msg_holder3${i}"></span>
										    </div>
										</td>
										<td>
											<a href="javascript:;" class="btn-danger btn-sm servicedel" data-id="${i}">删除</a>
										</td>
									  </tr>
								`
                                }else{
                                    htmlnew+=`
									  <tr id="${i}">
									    <input type="hidden" name="service_id${i}" value="${data[i].id}">  
										<td><input readonly class="nostyle" name="service_name${i}" value="${data[i].service_name}"></td>
										<td><input readonly class="nostyle" name="price${i}" value="${data[i].service_price}"></td>
										<td><input t-id="changefun" class="w70" type="number" min="0" data-rule="required"  data-msg-required="必填"  data-target="#msg_holder1${i}" class="nostyle" name="num${i}"  value="1" ><span class="msg-box" id="msg_holder1${i}"></span></td>
										<td><input readonly class="nostyle"  type="number"  min="0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder2${i}" class="nostyle" name="total${i}"  value="${data[i].service_price}" /><span class="msg-box" id="msg_holder2${i}"></span></td>
										<td>
										<div class="technician" data-index="${i}">
										    <div id="choose${i}" class="btn btn-primary"><i class="fa fa-list">选择</i>
										    <input type="hidden" name="design_id${i}" value="">
										    <input  data-rule="required" data-msg-required="必填"  data-target="#msg_holder3${i}" readonly class="nostyle" name="design_name${i}" style="display:none" value="">
										    </div>
										    <span  class="msg-box" id="msg_holder3${i}"></span>
										</div>
										</td>
										<td>
											<a href="javascript:;" class="btn-danger btn-sm servicedel" data-id="${i}">删除</a>
										</td>
									  </tr>
								`
                                }

                                total_money += parseFloat(data[i].service_price)


                            }

                            $("#service_table").html(htmlnew)

                            //会员优惠金额
                            let vip_amount = sessionStorage.getItem('discount') * total_money
                            //优惠金额
                            let couponDiscount= sessionStorage.getItem('coupon_discount')
                            if (couponDiscount) {
                                var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                                $("input[name='discount_amount']").val(discount_money.toFixed(2))
                            }
                            let discount_amount = $("input[name='discount_amount']").val()
                            //待付款金额
                            let real_amount = total_money - vip_amount - discount_amount;
                            $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                            //总价格
                            $("input[name='total_amount']").val(total_money.toFixed(2))



                        }else if(data!=''){//否则是单选
                            let  htmlnew=`
							<thead>
							  <tr>
								<th>服务名称</th>
								<th>单价</th>
								<th>数量</th>
								<th>小计</th>
								<th>技师</th>
								<th>操作</th>
							  </tr> 
							</thead>
							  <tr  id=0>
							    <input type="hidden" name="service_id0" value="${data.id}">  
								<td><input readonly class="nostyle" name="service_name0" value="${data.service_name}"></td>
								<td><input readonly class="nostyle" name="price0" value="${data.price}"></td>
								<td><input  t-id="changefun" id="serve_num0" class="w70" type="number"  min="0" class="nostyle"  data-rule="required" data-msg-required="必填"  data-target="#msg_holder1" name="num0" value="${data.num}" ><span class="msg-box" id="msg_holder1"></span></td>
								<td><input readonly id="total0" class="nostyle"  type="number" min="0" class="nostyle"  data-msg-required="必填"  data-target="#msg_holder2" data-rule="required" name="total0" value="${data.subtotal}" /><span class="msg-box" id="msg_holder2"></span></td>
								<td>
								<div class="technician" data-index="0">
                                    <div id="choose0" class="btn btn-primary"><i class="fa fa-list">选择</i>
                                    <input type="hidden" name="design_id0" value="">
                                    <input id="design_id0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder3" readonly class="nostyle" name="design_name0" style="display:none" value="">
                                    </div>
                                    <span  class="msg-box" id="msg_holder3"></span>
								</div>
								</td>
								<td>
									<a href="javascript:;" class="btn-danger btn-sm servicedel"data-id=0>删除</a>
								</td>
							  </tr>
						`

                            let total_money = parseFloat(data.price)
                            //会员优惠金额
                            let vip_amount = sessionStorage.getItem('discount') * total_money
                            //优惠金额
                            let couponDiscount= sessionStorage.getItem('coupon_discount')
                            if (couponDiscount) {
                                var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                                $("input[name='discount_amount']").val(discount_money.toFixed(2))
                            }
                            let discount_amount = $("input[name='discount_amount']").val()
                            //待付款金额
                            let real_amount = total_money - vip_amount - discount_amount;
                            $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                            //总价格
                            $("input[name='total_amount']").val(total_money.toFixed(2))

                            $("#service_table").html(htmlnew)
                        }

                        if($("#service_table").children().length>0){
                            $("#input_servename").val("1")
                        }else{
                            $("#input_servename").val("")
                        }
                    }})
                Controller.api.bindevent();
            })

            //优惠券
            $('#add-form').on('click', '.coupon', function() {
                var userId = sessionStorage.getItem('user_id') ? sessionStorage.getItem('user_id') : 0

                Fast.api.open('/shijiu.php/chase/real_order/coupons?user_id=' + userId, '优惠券列表',{callback: function (data) {
                        $("#tablebox").html(`<table id="table2" class="table table-bordered text-center" width="70%">
						 <thead>
						   <tr>
							 <th>优惠券名称</th>
							 <th>优惠金额</th>
							 <th>操作</th>
						   </tr> 
						 </thead>
						  <tbody>
							<tr>
							  <input type="hidden" name="user_coupon_id" value="${data.id}">  
							  <td><input readonly class="nostyle" name="coupon_name" value="${data.name}"></td>
							  <td><input readonly class="nostyle" name="coupon_price" value="${data.price}"></td>
							  <td>
								  <a href="javascript:;"  class="btn-danger btn-sm del">删除</a>
							  </td>
							</tr>
						  </tbody>
					</table>`)
                        $("#input_couponname").val("1")


                        //优惠金额
                        if (data.type == 1) {
                            var total_amount = $("input[name='total_amount']").val()
                            var vip_amount = $("input[name='vip_amount']").val()
                            var real_amount = total_amount - vip_amount - data.price
                            $("input[name='discount_amount']").val(data.price)
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                        }
                        if (data.type == 2) {
                            var total_amount = $("input[name='total_amount']").val()
                            var vip_amount = $("input[name='vip_amount']").val()
                            var discount_amount = (total_amount - vip_amount)* (10 - parseFloat(data.price)) / 10
                            var real_amount = total_amount - vip_amount - discount_amount
                            $("input[name='discount_amount']").val(discount_amount.toFixed(2))
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)                        }
                    }})
            })
            //删除优惠券
            $('#tablebox').on('click', '.del', function() {

                let total_amount = $("input[name='total_amount']").val()
                let vip_amount = $("input[name='vip_amount']").val()
                $("input[name='discount_amount']").val(0)
                $("input[name='real_amount']").val(total_amount - vip_amount)

                $("#tablebox").html('')
                $("#input_couponname").val("")//清空隐藏输入框的数据

            })
            //删除用户
            $('#userbox').on('click', '.userdel', function() {
                sessionStorage.removeItem('user_id')

                let total_amount = $("input[name='total_amount']").val()
                $("input[name='vip_amount']").val(0)
                $("input[name='discount_amount']").val(0)
                $("input[name='real_amount']").val(total_amount)


                $("#userbox").html('')
                $("#input_username").val("")//清空隐藏输入框的数据
                //删除优惠券
                $("#tablebox").html('')
                $("#input_couponname").val("")//清空隐藏输入框的数据
            })
            //删除服务
            $('#service_table').on('click', '.servicedel', function(str) {
                let id = $(this).data("id")

                let total_amount = $("input[name='total_amount']").val()
                let total = $("#service_table").find(`[name='total${id}']`).val()
                let total_money = total_amount - total;
                //会员优惠金额
                let vip_amount = sessionStorage.getItem('discount') * total_money
                //优惠金额
                let couponDiscount= sessionStorage.getItem('coupon_discount')
                if (couponDiscount) {
                    var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                    $("input[name='discount_amount']").val(discount_money.toFixed(2))
                }
                let discount_amount = $("input[name='discount_amount']").val()

                $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                //待付款金额
                let real_amount = total_money - vip_amount - discount_amount;
                $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                //总价格
                $("input[name='total_amount']").val(total_money.toFixed(2))

                $("#service_table").find(`tr[id='${id}']`).remove()

                if($('#service_table').find('tbody').children().length==0){
                    $("#service_table").find(`thead`).remove()
                }
                if($("#service_table").children().length>1){
                    $("#input_servename").val("1")
                }else{
                    $("#input_servename").val("")
                }

            })

            //选择造型师
            $('#add-form').on('click', '.technician', function() {
                //服务的下标
                let index = $(this).data('index')

                Fast.api.open('/shijiu.php/chase/real_order/designs', '技师',{callback: function (data) {

                        $(`#choose${index}`).find("i").remove()//删除选择的icon
                        $(`#choose${index}`).attr("class", "")//清空选择的样式
                        $(`#choose${index} input[name='design_id${index}']`).val(data.id)//把技师的名字替换上去
                        $(`#choose${index} input[name='design_name${index}']`).val(data.name)//把技师的名字替换上去
                        $(`#choose${index}`).find("input").css("display","block")//把技师的名字替换上去
                    }})
            })

            $('#add-form').on('click', '.entry', function(str) {
                sessionStorage.setItem('create-type', $(this).data('type'))
                $('#add-form').trigger("validate")
            })
            //提交表单
            $('#add-form').on('valid.form', function(e){
                let type = sessionStorage.getItem('create-type')
                //存放所有数据
                let allData ={}
                //获取服务数组
                let tabList=[];
                let tabListDom=$('#service_table tbody');
                let tabDom = $(tabListDom[0]).children();
                if(tabDom.length>0){
                    // console.log(tabDom)
                    for(let i=0;i<tabDom.length;i++){
                        let thisDom = $(tabDom[i]);
                        let thisIndex = thisDom.prop('id');
                        let nowObj = {
                            service_id:$(tabDom[i]).find(`[name=service_id${thisIndex}]`).val(),
                            service_name:$(tabDom[i]).find(`[name=service_name${thisIndex}]`).val(),
                            price:$(tabDom[i]).find(`[name=price${thisIndex}]`).val(),
                            num:$(tabDom[i]).find(`[name=num${thisIndex}]`).val(),
                            total:$(tabDom[i]).find(`[name=total${thisIndex}]`).val(),
                            design_id:$(tabDom[i]).find(`[name=design_id${thisIndex}]`).val(),
                        }
                        tabList.push(nowObj)
                        allData.services=tabList
                    }
                }
                //获取用户数据
                let tabListDom2=$('#table1 tbody');
                let tabDom2 = $(tabListDom2[0]).children();
                if(tabDom2.length>0){
                    allData.user_id=$(tabDom2[0]).find(`[name=user_id]`).val()
                    allData.nickname=$(tabDom2[0]).find(`[name=nickname]`).val()
                    allData.vip=$(tabDom2[0]).find(`[name=vip]`).val()
                    allData.phone=$(tabDom2[0]).find(`[name=phone]`).val()
                }
                //获取优惠券数据
                let tabListDom3=$('#table2 tbody');
                let tabDom3 = $(tabListDom3[0]).children();
                if(tabDom3.length>0){
                    allData.user_coupon_id=$(tabDom3[0]).find(`[name=user_coupon_id]`).val()
                    allData.coupon_name=$(tabDom3[0]).find(`[name=coupon_name]`).val()
                    allData.coupon_price=$(tabDom3[0]).find(`[name=coupon_price]`).val()
                }
                //获取会员优惠金额;待付款金额等
                allData.real_amount=$("input[name='real_amount']").val()
                allData.discount_amount=$("input[name='discount_amount']").val()
                allData.total_amount=$("input[name='total_amount']").val()
                allData.vip_amount=$("input[name='vip_amount']").val()
                allData.type = type

                //挂单或付款
                $.post('/shijiu.php/chase/real_order/add', allData, function (res) {

                    if (res.code == 1) {
                        sessionStorage.removeItem('user_id')
                        sessionStorage.removeItem('discount')
                        sessionStorage.removeItem('create-type')
                        sessionStorage.removeItem('coupon_discount')
                        if (type == 1) {
                            //付款页面
                            Fast.api.open('/shijiu.php/chase/real_order/payment?ids='+res.data.id, '收款', {
                                area:['70%', '70%']})
                        }
                        if (type == 2) {
                            //确认付款页面
                            Fast.api.open('/shijiu.php/chase/real_order/confirm?ids='+res.data.id, '收款', {area:['70%', '70%']})
                        }
                    } else {
                        layer.msg(res.msg)
                        return false
                    }
                })

            });

            $("#add-form").validator({
                fields: {//配置规则
                    input_username:'required',
                    input_servename:'required;',
                    // input_couponname:'required;'
                },
                messages: {//定制校验失败提示

                },
                valid: function (e) {//验证通过，回调
                }
            }).trigger("validate");
            Controller.api.bindevent();

        },
        payment: function () {
            let that = this
            $('#add-form').on('click', '.btn-user', function() {
                Fast.api.open('/shijiu.php/chase/real_order/users', '用户列表',{callback: function (data) {

                        $("#userbox").html(`<table id="table1" class="table table-bordered text-center" width="70%">
					<thead>
					   <tr>
						 <th>客户名称</th>
						 <th>会员等级</th>
						 <th>手机号码</th>
						 <th>操作</th>
					   </tr> 
					</thead>
						  <tbody>
							<tr>
							  <input type="hidden" name="user_id" value="${data.id}">  
							  <td><input readonly class="nostyle" name="nickname" value="${data.nickname}"></td>
							  <td><input readonly class="nostyle" name="vip" value="${data.vip}"></td>
							  <td><input readonly class="nostyle" name="phone" value="${data.phone}"></td>
							  <td>
								  <a href="javascript:;"  class="btn-danger btn-sm userdel">删除</a>
							  </td>
							</tr>
						  </tbody>
					</table>`)
                        $("#input_username").val("1")

                        let total_money = $("input[name='total_amount']").val()
                        let discount_amount = $("input[name='discount_amount']").val()
                        //会员优惠金额
                        let vip_amount = sessionStorage.getItem('discount') * parseFloat(total_money)
                        $("input[name='vip_amount']").val(vip_amount.toFixed(2))

                        //待付款金额
                        let real_amount = total_money - vip_amount - discount_amount;
                        $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)


                    }})

            })
            //数量改变事件
            $('#add-form').on('change',"input[t-id='changefun']",function(){
                let tabList=[];
                let tabListDom=$('#service_table tbody');
                let tabDom = $(tabListDom[0]).children();
                let total_money = 0;
                if(tabDom.length>0){
                    for(let i=0;i<tabDom.length;i++){
                        let thisDom = $(tabDom[i]);
                        let thisIndex = thisDom.prop('id');
                        let nowObj = {
                            service_name:$(tabDom[i]).find(`[name='service[${thisIndex}][service_name]']`).val(),
                            price:$(tabDom[i]).find(`[name='service[${thisIndex}][price]']`).val(),
                            num:$(tabDom[i]).find(`[name='service[${thisIndex}][num]']`).val(),
                            // total:$(tabDom[i]).find(`[name=total${thisIndex}]`).val(),
                            design_id:$(tabDom[i]).find(`[name='service[${thisIndex}][design_id]']`).val(),
                        }
                        nowObj.total = nowObj.price * nowObj.num
                        tabList.push(nowObj)
                        total_money += nowObj.total
                        $(`input[name='service[${thisIndex}][total]']`).val(nowObj.total.toFixed(2))
                    }

                    //会员优惠金额
                    let vip_discount = $("input[name='vip_discount']").val()
                    let vip_amount = vip_discount != undefined ?  vip_discount * total_money : sessionStorage.getItem('discount') * total_money
                    //优惠金额
                    let coupon_discount = $("input[name='coupon_discount']").val()
                    let couponDiscount = coupon_discount && coupon_discount != undefined ? coupon_discount : sessionStorage.getItem('coupon_discount')

                    if (couponDiscount) {
                        var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                        $("input[name='discount_amount']").val(discount_money.toFixed(2))
                    }
                    let discount_amount = $("input[name='discount_amount']").val()
                    //待付款金额
                    let real_amount = total_money - vip_amount - discount_amount;
                    $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                    $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                    //总价格
                    $("input[name='total_amount']").val(total_money.toFixed(2))
                }
                console.log(tabList)
            })
            //服务
            $('#add-form').on('click', '.service', function() {
                Fast.api.open('/shijiu.php/chase/real_order/services', '服务列表',{callback: function (data) {

                        //如果返回的事一个数组是多选服务
                        if(data.length>0){
                            let htmlnew=''
                            let total_money = 0;
                            for(let i = 0 ;i<data.length;i++){
                                if(i==0){
                                    htmlnew=`
									<thead>
									  <tr>
										<th>服务名称</th>
										<th>单价</th>
										<th>数量</th>
										<th>小计</th>
										<th>技师</th>
										<th>操作</th>
									  </tr> 
									</thead>
									  <tr id="${i}">
									    <input type="hidden" name="service[${i}][service_id]" value="${data.id}">  
										<td><input readonly class="nostyle" name="service[${i}][service_name]" value="${data[i].service_name}"></td>
										<td><input readonly class="nostyle" name="service[${i}][price]" value="${data[i].service_price}"></td>
										<td><input t-id="changefun" class="w70" type="number" min="0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder1${i}" class="nostyle" name="service[${i}][num]" value="1" ><span class="msg-box" id="msg_holder1${i}"></span></td>
										<td><input readonly class="nostyle"  type="number" min="0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder2${i}" class="nostyle" name="service[${i}][total]" value="${data[i].service_price}" /><span class="msg-box" id="msg_holder2${i}"></span></td>
										<td>
										    <div class="technician" data-index="${i}">
                                                <div id="choose${i}" class="btn btn-primary"><i class="fa fa-list">选择</i>
                                                <input type="hidden" name="service[${i}][design_id]" value="">
                                                <input readonly class="nostyle" data-rule="required" data-msg-required="必填"  data-target="#msg_holder3${i}" name="service[${i}][design_name]" style="display:none" value="">
                                                </div>
                                                <span  class="msg-box" id="msg_holder3${i}"></span>
										    </div>
										</td>
										<td>
											<a href="javascript:;" class="btn-danger btn-sm servicedel" data-id="${i}">删除</a>
										</td>
									  </tr>
								`
                                }else{
                                    htmlnew+=`
									  <tr id="${i}">
									    <input type="hidden" name="service[${i}][service_id]" value="${data.id}">  
										<td><input readonly class="nostyle" name="service[${i}][service_name]" value="${data[i].service_name}"></td>
										<td><input readonly class="nostyle" name="service[${i}][price]" value="${data[i].service_price}"></td>
										<td><input t-id="changefun" class="w70" type="number" min="0" data-rule="required"  data-msg-required="必填"  data-target="#msg_holder1${i}" class="nostyle" name="service[${i}][num]"  value="1" ><span class="msg-box" id="msg_holder1${i}"></span></td>
										<td><input readonly class="nostyle"  type="number"  min="0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder2${i}" class="nostyle" name="service[${i}][total]"  value="${data[i].service_price}" /><span class="msg-box" id="msg_holder2${i}"></span></td>
										<td>
										<div class="technician" data-index="${i}">
										    <div id="choose${i}" class="btn btn-primary"><i class="fa fa-list">选择</i>
										    <input type="hidden" name="service[${i}][design_id]" value="">
										    <input  data-rule="required" data-msg-required="必填"  data-target="#msg_holder3${i}" readonly class="nostyle" name="service[${i}][design_name]" style="display:none" value="">
										    </div>
										    <span  class="msg-box" id="msg_holder3${i}"></span>
										</div>
										</td>
										<td>
											<a href="javascript:;" class="btn-danger btn-sm servicedel" data-id="${i}">删除</a>
										</td>
									  </tr>
								`
                                }

                                total_money += parseFloat(data[i].service_price)

                            }

                            $("#service_table").html(htmlnew)

                            //会员优惠金额
                            let vip_discount = $("input[name='vip_discount']").val()

                            let vip_amount = vip_discount != undefined ?  vip_discount * total_money : sessionStorage.getItem('discount') * total_money
                            //优惠金额
                            let coupon_discount = $("input[name='coupon_discount']").val()
                            let couponDiscount = coupon_discount && coupon_discount != undefined ? coupon_discount : sessionStorage.getItem('coupon_discount')
                            if (couponDiscount) {
                                var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                                $("input[name='discount_amount']").val(discount_money.toFixed(2))
                            }
                            let discount_amount = $("input[name='discount_amount']").val()

                            $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                            //待付款金额
                            let real_amount = total_money - vip_amount - discount_amount;
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                            //总价格
                            $("input[name='total_amount']").val(total_money.toFixed(2))


                        }else if(data!=''){//否则是单选
                            let  htmlnew=`
							<thead>
							  <tr>
								<th>服务名称</th>
								<th>单价</th>
								<th>数量</th>
								<th>小计</th>
								<th>技师</th>
								<th>操作</th>
							  </tr> 
							</thead>
							  <tr id="0">
							    <input type="hidden" name="service[0][service_id]" value="${data.id}">  
								<td><input readonly class="nostyle" name="service[0][service_name]" value="${data.service_name}"></td>
								<td><input readonly class="nostyle" name="service[0][price]" value="${data.price}"></td>
								<td><input id="serve_num0" t-id="changefun" class="w70" type="number"  min="0" class="nostyle"  data-rule="required" data-msg-required="必填"  data-target="#msg_holder1" name="service[0][num]" value="${data.num}" ><span class="msg-box" id="msg_holder1"></span></td>
								<td><input readonly id="total0" class="nostyle"  type="number" min="0" class="nostyle"  data-msg-required="必填"  data-target="#msg_holder2" data-rule="required" name="service[0][total]" value="${data.subtotal}" /><span class="msg-box" id="msg_holder2"></span></td>
								<td>
								<div class="technician" data-index="0">
                                    <div id="choose0" class="btn btn-primary"><i class="fa fa-list">选择</i>
                                    <input type="hidden" name="service[0][design_id]" value="">
                                    <input id="design_id0" data-rule="required" data-msg-required="必填"  data-target="#msg_holder3" readonly class="nostyle" name="service[0][design_name]" style="display:none" value="">
                                    </div>
                                    <span  class="msg-box" id="msg_holder3"></span>
								</div>
								</td>
								<td>
									<a href="javascript:;" class="btn-danger btn-sm servicedel"data-id=0>删除</a>
								</td>
							  </tr>
						`
                            let total_money = parseFloat(data.price)
                            //会员优惠金额
                            let vip_discount = $("input[name='vip_discount']").val()

                            let vip_amount = vip_discount != undefined ?  vip_discount * total_money : sessionStorage.getItem('discount') * total_money
                            //优惠金额
                            let coupon_discount = $("input[name='coupon_discount']").val()
                            let couponDiscount = coupon_discount && coupon_discount != undefined ? coupon_discount : sessionStorage.getItem('coupon_discount')
                            if (couponDiscount) {
                                var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                                $("input[name='discount_amount']").val(discount_money.toFixed(2))
                            }

                            let discount_amount = $("input[name='discount_amount']").val()

                            $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                            //待付款金额
                            let real_amount = total_money - vip_amount - discount_amount;
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                            //总价格
                            $("input[name='total_amount']").val(total_money.toFixed(2))

                            $("#service_table").html(htmlnew)
                        }

                        if($("#service_table").children().length>0){
                            $("#input_servename").val("1")
                        }else{
                            $("#input_servename").val("")
                        }
                    }})

            })

            //优惠券
            $('#add-form').on('click', '.coupon', function() {

                let userId = sessionStorage.getItem('user_id')

                Fast.api.open('/shijiu.php/chase/real_order/coupons?user_id=' + userId, '优惠券列表',{callback: function (data) {
                        $("#tablebox").html(`<table id="table2" class="table table-bordered text-center" width="70%">
						 <thead>
						   <tr>
							 <th>优惠券名称</th>
							 <th>优惠金额</th>
							 <th>操作</th>
						   </tr> 
						 </thead>
						  <tbody>
							<tr>
							  <input type="hidden" name="user_coupon_id" value="${data.id}">  
							  <td><input readonly class="nostyle" name="coupon_name" value="${data.name}"></td>
							  <td><input readonly class="nostyle" name="coupon_price" value="${data.price}"></td>
							  <td>
								  <a href="javascript:;"  class="btn-danger btn-sm del">删除</a>
							  </td>
							</tr>
						  </tbody>
					</table>`)
                        $("#input_couponname").val("1")


                        //优惠金额
                        if (data.type == 1) {
                            var total_amount = $("input[name='total_amount']").val()
                            var vip_amount = $("input[name='vip_amount']").val()
                            var real_amount = total_amount - vip_amount - data.price
                            $("input[name='discount_amount']").val(data.price)
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                        }
                        if (data.type == 2) {
                            var total_amount = $("input[name='total_amount']").val()
                            var vip_amount = $("input[name='vip_amount']").val()
                            var discount_amount = (total_amount - vip_amount)* (10 - parseFloat(data.price)) / 10
                            var real_amount = total_amount - vip_amount - discount_amount
                            $("input[name='discount_amount']").val(discount_amount.toFixed(2))
                            $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)                        }
                    }})
            })
            //删除优惠券
            $('#tablebox').on('click', '.del', function() {

                let total_amount = $("input[name='total_amount']").val()
                let vip_amount = $("input[name='vip_amount']").val()
                $("input[name='discount_amount']").val(0)
                $("input[name='real_amount']").val(total_amount - vip_amount)

                $("#tablebox").html('')
                $("#input_couponname").val("")//清空隐藏输入框的数据
            })
            //删除用户
            $('#userbox').on('click', '.userdel', function() {
                sessionStorage.removeItem('user_id')

                let total_amount = $("input[name='total_amount']").val()
                $("input[name='vip_amount']").val(0)
                $("input[name='discount_amount']").val(0)
                $("input[name='real_amount']").val(total_amount)

                $("#userbox").html('')
                $("#input_username").val("")//清空隐藏输入框的数据
                //删除优惠券
                $("#tablebox").html('')
                $("#input_couponname").val("")//清空隐藏输入框的数据
            })
            //删除服务
            $('#service_table').on('click', '.servicedel', function(str) {
                let id = $(this).data("id")

                let total_amount = $("input[name='total_amount']").val()
                let total = $("#service_table").find(`[name='service[${id}][total]']`).val()
                let total_money = total_amount - total;
                //会员优惠金额
                let vip_amount = sessionStorage.getItem('discount') * total_money
                //优惠金额
                let couponDiscount= sessionStorage.getItem('coupon_discount')
                if (couponDiscount) {
                    var discount_money = (total_money - vip_amount) * (10 - couponDiscount) / 10
                    $("input[name='discount_amount']").val(discount_money.toFixed(2))
                }
                let discount_amount = $("input[name='discount_amount']").val()

                $("input[name='vip_amount']").val(vip_amount.toFixed(2))
                //待付款金额
                let real_amount = total_money - vip_amount - discount_amount;
                $("input[name='real_amount']").val(real_amount > 0 ? real_amount.toFixed(2) : 0)
                //总价格
                $("input[name='total_amount']").val(total_money.toFixed(2))


                $("#service_table").find(`tr[id='${id}']`).remove()

                if($('#service_table').find('tbody').children().length==0){
                    $("#service_table").find(`thead`).remove()
                }
                if($("#service_table").children().length>1){
                    $("#input_servename").val("1")
                }else{
                    $("#input_servename").val("")
                }
            })

            //选择造型师
            $('#add-form').on('click', '.technician', function() {
                //服务的下标
                let index = $(this).data('index')

                Fast.api.open('/shijiu.php/chase/real_order/designs', '技师',{callback: function (data) {

                        $(`#choose${index}`).find("i").remove()//删除选择的icon
                        $(`#choose${index}`).attr("class", "")//清空选择的样式
                        $(`#choose${index} input[name='design_id${index}']`).val(data.id)//把技师的名字替换上去
                        $(`#choose${index} input[name='design_name${index}']`).val(data.name)//把技师的名字替换上去
                        $(`#choose${index}`).find("input").css("display","block")//把技师的名字替换上去
                    }})
            })


            //付款方式
            $("input[name='payment']").on('change', function () {
                payment = $(this).val()
                if (payment == 3) {
                    $('.img').show()
                } else {
                    $('.img').hide()
                }
            })

            var user_id = $("input[name='user_id']").val()
            sessionStorage.setItem('user_id', user_id)



            Controller.api.bindevent();

        },
        //选择用户
        users: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    table: 'test',
                }
            });
            var table = $("#table");
            //当表格数据加载完成时
            table.bootstrapTable({
                url: '/shijiu.php/chase/real_order/users',
                columns: [{
                    field: 'id',
                    title: '用户ID',
                    operate: false
                }, {
                    field: 'nickname',
                    title: '用户名称',
                    operate: 'like'
                }, {
                    field: 'vip',
                    title: '会员等级',
                    operate: false,
                    formatter: Table.api.formatter.label
                }, {
                    field: 'phone',
                    title: '手机号码'
                },
                    {
                        operate:false,
                        field: 'column_operate',
                        title: '操作',
                        formatter: function(value, row, index) {
                            return `<a href="javascript:;" data-discount="${row.discount}" data-id="${row.id}" data-nickname="${row.nickname}" data-vip="${row.vip}" data-phone="${row.phone}" class="btn btn-danger selected btn-xs"><i class="fa fa-check"></i>选择</a>`;
                        },
                    }
                ]

            });

            //选择用户
            $('.content').on('click', '.user-add', function() {
                Fast.api.open('/shijiu.php/chase/real_order/adduser', '添加用户')
            })
            //选中的用户
            $('#table').on('click', '.selected', function() {
                //缓存用户id
                sessionStorage.setItem('user_id', $(this).data('id'))
                sessionStorage.setItem('discount', $(this).data('discount'))

                let data={
                    id: $(this).data('id'),
                    nickname: $(this).data('nickname'),
                    vip: $(this).data('vip'),
                    phone: $(this).data('phone')
                }
                var index = parent.Layer.getFrameIndex(window.name);
                var callback = parent.$("#layui-layer" + index).data("callback");
                //再执行关闭
                parent.Layer.close(index);
                //再调用回传函数
                if (typeof callback === 'function') {
                    callback.call(undefined, data);
                }
            })

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        adduser: function () {
            Controller.api.bindevent();
        },
        //选择服务
        services:function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    table: 'services',
                }
            });
            var table = $("#table");
            //当表格数据加载完成时
            table.bootstrapTable({
                url: '/shijiu.php/chase/real_order/services',
                columns: [
                    {
                        checkbox: true,
                        visible: true                  //是否显示复选框
                    },{
                        field: 'service_name',
                        title: '服务名称',
                        operate: 'like'
                    }, {
                        field: 'service_price',
                        title: '单价'
                    },
                    {
                        operate:false,
                        field: 'column_operate',
                        title: '操作',
                        formatter: function(value, row, index) {
                            return `<a href="" data-id="${row.id}" data-service_name="${row.service_name}" data-price="${row.service_price}" data-num="1" data-subtotal="${row.service_price}" data-technician_name="" class="btn btn-danger alone_choose btn-xs"><i class="fa fa-check"></i>选择</a>`;
                        },
                    }
                ]

            });
            //选中的服务
            $('#table').on('click', '.alone_choose', function() {
                // data-name="${row.name}" data-price="${row.price}" data-num="${row.num}" data-technician_name="${row.technician_name}"
                let data={
                    id: $(this).data('id'),
                    service_name: $(this).data('service_name'),
                    price: $(this).data('price'),
                    num: $(this).data('num'),
                    subtotal: $(this).data('subtotal'),
                    technician_name: $(this).data('technician_name')
                }
                var index = parent.Layer.getFrameIndex(window.name);
                var callback = parent.$("#layui-layer" + index).data("callback");
                //再执行关闭
                parent.Layer.close(index);
                //再调用回传函数
                if (typeof callback === 'function') {
                    callback.call(undefined, data);
                }
                parent.Layer.close(index);
            })
            $('#add-form').on('click', '.btn-choose', function() {
                var idlist = $('#table').bootstrapTable('getAllSelections');
                var index = parent.Layer.getFrameIndex(window.name);
                var callback = parent.$("#layui-layer" + index).data("callback");
                //再执行关闭
                parent.Layer.close(index);
                //再调用回传函数
                if (typeof callback === 'function') {
                    callback.call(undefined, idlist);
                }
                parent.Layer.close(index);

            })
            // 为表格绑定事件
            Table.api.bindevent(table);
            Controller.api.bindevent();
        },
        //优惠券
        coupons: function (e) {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    table: 'test',
                }
            });
            var table = $("#table");

            let userId = sessionStorage.getItem('user_id')

            //当表格数据加载完成时
            table.bootstrapTable({
                url: '/shijiu.php/chase/real_order/coupons?user_id='+userId,
                columns: [{
                    field: 'id',
                    title: 'ID'
                }, {
                    field: 'coupon_name',
                    title: '优惠券名称'
                }, {
                    field: 'need_amount',
                    title: '满足金额'
                }, {
                    field: 'discount_amount',
                    title: '优惠金额'
                }, {
                    field: 'start_time',
                    title: '开始时间'
                },  {
                    field: 'end_time',
                    title: '结束时间'
                }, {
                        operate:false,
                        field: 'column_operate',
                        title: '操作',
                        formatter: function(value, row, index) {
                            return `<a href="" data-id="${row.id}" data-type="${row.type}" data-name="${row.coupon_name}" data-price="${row.discount_amount}" class="btn btn-danger coupon-click btn-chooseone btn-xs"><i class="fa fa-check"></i>选择</a>`;
                        },
                    }
                ]

            });
            // 为表格绑定事件
            Table.api.bindevent(table);

            $('#table').on('click', '.coupon-click', function() {

                var price = $(this).data('price')
                var type = $(this).data('type')
                if (type == 1) {
                    sessionStorage.removeItem('coupon_discount')
                }
                if (type == 2) {
                    price = price + '折'
                    sessionStorage.setItem('coupon_discount', $(this).data('price'))
                }

                let data={
                    id: $(this).data('id'),
                    name: $(this).data('name'),
                    price: price,
                    type: type
                }

                var index = parent.Layer.getFrameIndex(window.name);
                var callback = parent.$("#layui-layer" + index).data("callback");
                //再执行关闭
                parent.Layer.close(index);
                //再调用回传函数
                if (typeof callback === 'function') {
                    callback.call(undefined, data);
                }
            })

        },
        //造型师
        designs:function(){
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    table: 'test',
                }
            });
            var table = $("#table");
            //当表格数据加载完成时
            table.bootstrapTable({
                url: '/shijiu.php/chase/real_order/designs',
                columns: [{
                    field: 'id',
                    title: 'ID',
                    operate: false
                },  {
                    field: 'nickname',
                    title: '技师名称',
                    operate: 'like'
                },
                    {
                        operate:false,
                        field: 'column_operate',
                        title: '操作',
                        formatter: function(value, row, index) {
                            return `<a href="" data-id="${row.id}" data-name="${row.nickname}" class="btn btn-danger selected btn-xs"><i class="fa fa-check"></i>选择</a>`;
                        },
                    }
                ]

            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $('#table').on('click', '.selected', function() {
                let data={
                    id: $(this).data('id'),
                    name: $(this).data('name')
                }
                var index = parent.Layer.getFrameIndex(window.name);
                var callback = parent.$("#layui-layer" + index).data("callback");
                //再执行关闭
                parent.Layer.close(index);
                //再调用回传函数
                if (typeof callback === 'function') {
                    callback.call(undefined, data);
                }
            })
            //提交表单
            $('#technician-form').on('valid.form', function(e){
                // You can do something, then submit form by native
                // this.submit();
                // or use ajax submit
                console.log($(this).serialize())
            });

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        confirm: function () {

            $("input[name='payment']").on('change', function () {
                payment = $(this).val()
                if (payment == 3) {
                    $('.img').show()
                } else {
                    $('.img').hide()
                }
            })

            Controller.api.bindevent();
        },
        api: {
            order_info:function(value, row, index){
                var number = '订单编号: ' + row.order_no + '<br>';
                var time = '下单时间: ' + row.createtime + '<br>';
                return number  + time
            },
            user_info:function(value, row, index){
                nickname = row.user ? row.user.nickname : 111;
                telphone = row.user ? row.user.phone : 111;
                vip = row.user ? row.user.vip : 111;

                var name = "客户名称:" + nickname + '<br>';
                var phone = "客户手机:" + telphone + '<br>';
                var grade = "用户等级:" + vip + '<br>';
                return name  + phone  + grade
            },
            service_name:function(value, row, index){
                // console.log(value, row, index)
                if(row.service.length>0){
                    let service_html=`
					<table innertable >
					`
                    for (var i = 0; i < row.service.length; i++) {
                        // console.log(row.service[i].service_name)
                        service_html+=`
								<tr><td style="${i>0?'border-top:1px solid #f4f4f4':''}">${row.service[i].service_name}</td></tr>
							`
                    }
                    return service_html+=`</table>`
                }
            },
            service_price:function(value, row, index){
                // console.log(value, row, index)
                if(row.service.length>0){
                    let service_html=`
					<table id="innertable">
					`
                    for (var i = 0; i < row.service.length; i++) {
                        // console.log(row.service[i].price)
                        service_html+=`
								<tr><td style="${i>0?'border-top:1px solid #f4f4f4':''}">${row.service[i].price}</td></tr>
							`
                    }
                    return service_html+=`</table>`
                }
            },
            service_count:function(value, row, index){
                // console.log(value, row, index)
                if(row.service.length>0){
                    let service_html=`
					<table id="innertable">
					`
                    for (var i = 0; i < row.service.length; i++) {
                        // console.log(row.service[i].count)
                        service_html+=`
								<tr><td style="${i>0?'border-top:1px solid #f4f4f4':''}">x${row.service[i].num}</td></tr>
							`
                    }
                    return service_html+=`</table>`
                }
            },
            service_technician:function(value, row, index){
                // console.log(value, row, index)
                if(row.service.length>0){
                    let service_html=`
					<table id="innertable">
					`
                    for (var i = 0; i < row.service.length; i++) {
                        // console.log(row.service[i].technician)
                        var design_name = row.service[i].design ? row.service[i].design.nickname : ''

                        service_html+=`
								<tr><td style="${i>0?'border-top:1px solid #f4f4f4':''}">${design_name}</td></tr>
							`
                    }
                    return service_html+=`</table>`
                }
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }

    };
    return Controller;
});